#ifndef POOL_H
#define POOL_H

#include "config.h"
#include "logger.h"

#include <pthread.h>

#include <list>

#include <pqxx/connection>

class ConnectionPool {

private:    
    Config cfg;

    pthread_mutex_t pool_list_mutex; //!< Controls the access to the STL list pool_list.
    std::list<pqxx::connection*> pool_list; //!< The list of all available(not used) connections.

    pqxx::connection* create_db_conn();
    void delete_db_conn(pqxx::connection* conn);
    void close_all_conn();
public:
    ConnectionPool(const Config& ); 

    ~ConnectionPool();

    pqxx::connection* get_connection();
    void put_connection(pqxx::connection* conn);
};

#endif
